//
//  ASPoliticalInfoVC.m
//  AttendenceSys
//
//  Created by 窦芳俊 on 16/4/18.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASPoliticalInfoVC.h"

#define kPoliticalInfoCellHeight 50

@interface ASPoliticalInfoVC () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *politicalTableView;
@property (nonatomic, strong) NSMutableArray* pArray;

@end


@implementation ASPoliticalInfoVC

- (instancetype)initWithPoliticalInfoArray:(NSMutableArray *)array
{
    self = [super init];
    if (self)
    {
        _pArray = array;
    }
    
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.strNavTitle = @"政治面貌";
    self.view.backgroundColor = [UIColor whiteColor];
    
    _politicalTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _politicalTableView.frame = CGRectMake(0, 0, self.view.frame.size.width, [_pArray count] * kPoliticalInfoCellHeight);
    _politicalTableView.delegate = self;
    _politicalTableView.dataSource = self;
    _politicalTableView.backgroundColor = [UIColor whiteColor];
    _politicalTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    _politicalTableView.rowHeight = kPoliticalInfoCellHeight;
    [self.view addSubview:_politicalTableView];
    
    [_politicalTableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_pArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"politicalInfoTableViewCellIdentifier"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] init];
    }
    
    ASPoliticalInfo *info = [_pArray objectAtIndex:[indexPath row]];
    cell.textLabel.text = info.politicalName;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(selectPoliInfo:)])
    {
        ASPoliticalInfo *info = [_pArray objectAtIndex:[indexPath row]];
        [self.delegate selectPoliInfo:info];
    }
}



@end




